package v3.chapter4.lockMethodTest3;

import java.util.concurrent.locks.ReentrantLock;

public class Run2 {

	public static void main(String[] args) {
		final Service2 service1 = new Service2(true);
		Runnable runnable = new Runnable() {
			@Override
			public void run() {
				service1.serviceMethod();
			}
		};
		Thread thread = new Thread(runnable);
		thread.start();

	}

}

class Service2 {

	private ReentrantLock lock;

	public Service2(boolean isFair) {
		super();
		lock = new ReentrantLock(isFair);
	}

	public void serviceMethod() {
		try {
			System.out.println(lock.isHeldByCurrentThread());
			lock.lock();
			System.out.println(lock.isHeldByCurrentThread());
		} finally {
			lock.unlock();
		}
	}
}
